package com.ming.seatMonitoring.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.seatMonitoring.pojo.DO.RoomInfoDO;
import com.ming.seatMonitoring.pojo.entity.ResultBody;
import com.ming.seatMonitoring.service.RoomInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.sql.Wrapper;
import java.util.Date;

/**
 * @author 小明
 * @date 2021/10/21
 * @description
 */
@RequestMapping("/roomInfo")
@RestController
public class RoomInfoController {

    @Autowired
    private RoomInfoService roomInfoService;

    /**
     * 增加房间信息
     * @param roomInfoDO
     * @return
     */
    @RequestMapping("add")
    public ResultBody addRoomInfo(@RequestBody @NotEmpty RoomInfoDO roomInfoDO){
        final boolean b = roomInfoService.addRoomInfo(roomInfoDO);
        if (b){
            return ResultBody.ok().message("添加成功");
        }
        return ResultBody.ok().message("添加失败，请重试");
    }

    /**
     * 伪删除房间信息，添加deleteTime
     * @param roomId
     * @return
     */
    @RequestMapping("/delete")
    public ResultBody deleteRoomInfo(@RequestParam int roomId){
        final boolean b = roomInfoService.deleteRoomInfo(roomId);
        System.out.println(b);
        if (b){
            return ResultBody.ok().message("删除成功");
        }
        return ResultBody.error().message("删除失败，请重试");
    }

    /**
     * 更新房间信息
     * @param roomInfoDO
     * @return
     */
    @RequestMapping("/update")
    public ResultBody updateRoomInfo(@RequestBody RoomInfoDO roomInfoDO){

        final boolean b = roomInfoService.updateRoomInfo(roomInfoDO);
        if (b){
            return ResultBody.ok().message("更新成功");
        }
        return ResultBody.ok().message("更新失败，请重试");
    }

    /**
     * 分页查询所有房间
     * @param pageNumber  当前页数
     * @param size  每页大小
     * @return
     */
    @RequestMapping("/selectPage")
    public ResultBody selectRoomInfo(@RequestParam(defaultValue = "1") @NotEmpty String pageNumber,
                                     @RequestParam(defaultValue = "10") @NotEmpty String size){
        Long PageNumber = Long.valueOf(pageNumber);
        Long Size = Long.valueOf(size);
        Page<RoomInfoDO> page = new Page<>(PageNumber,Size);
        Page<RoomInfoDO> roomInfo = roomInfoService.getRoomInfo(page);
        return ResultBody.ok().data("roomInfo",roomInfo);
    }

    @RequestMapping("/searchById")
    public ResultBody selectRoomInfoById(@RequestParam("roomId") int roomId){

        return ResultBody.ok().data("roomInfo",roomInfoService.searchRoom(roomId));
    }
}
